function Person() {
}

Person.prototype.walk = function () {
    console.dir('walk')
}
Person.prototype.sayHello = function () {
    console.dir('sayHello')
}

// 以下的三步，是继承实现的关键
function Student() {
    Person.call(this)
}
// 让被继承 function 的原型出现在对象的原型链中
// inherit Person
Student.prototype = Object.create(Person.prototype)
// correct the constructor pointer because it points to Person
Student.prototype.constructor = Student

// replace the sayHello method
Student.prototype.sayHello = function () {
    console.dir('hi, I am a student');
}

// add sayGoodBye method
Student.prototype.sayGoodBye = function () {
    console.dir('goodBye');
}

let student1 = new Student();
student1.sayHello();
student1.walk();
student1.sayGoodBye();

// check inheritance
console.dir(student1 instanceof Person); // true
console.dir(student1 instanceof Student); // true
